﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Manage_InfoUpdate : System.Web.UI.Page
{
    public string strName1, strContent1;
    public string InfoId;
    protected void Page_Load(object sender, EventArgs e)
    {
        string strName, strContent;
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            if (!IsPostBack)
            {
                string strSql;
                if (Request.QueryString["InfoId"] != null)
                    InfoId = SysFun.IsSQL(Request.QueryString["InfoId"].ToString());
                else
                    return;
                strSql = "select * from info where infoid=" + InfoId;
                Db DbInfo = new Db();
                System.Data.IDataReader dr;
                dr = DbInfo.DataReader(strSql);
                if (dr.Read())
                {
                    //txtTitle.Text = dr["Title"].ToString();
                    //txtContent.Text = dr["Content"].ToString();
                    txtAccountId.Text = dr["AccountId"].ToString();
                    txtAccountId.Visible = false;
                    txtAddDate.Text = Convert.ToDateTime(dr["AddDate"].ToString()).ToShortDateString();
                    txtInfoId.Text = dr["InfoId"].ToString();
                    txtInfoId.Visible = false;
                    strName1 = dr["Title"].ToString();
                    strContent1 = dr["Content"].ToString();

                }
                dr.Close();
                dr.Dispose();
                DbInfo.Close();
            }
            strName = SysFun.ToTrim(Request.Form["txtName"]);
            strContent = SysFun.ToTrim(Request.Form["txtContentHtml"]);
            if (strName != "" && strContent != "")
            {
                Db db1 = new Db();
                Grove.ORM.ObjectOperator oo = db1.GetObjectOperator();
                HZ.MBSM.Model.Info Info = new HZ.MBSM.Model.Info();
                Info.Infoid = Convert.ToInt64(txtInfoId.Text);
                Info.Title = strName;
                //dr["Content"].ToString().Replace("\r\n","<br>")
                Info.Content = strContent.Replace("\r\n", "");
                Info.AccountId = Convert.ToInt64(txtAccountId.Text);
                Info.AddDate = Convert.ToDateTime(txtAddDate.Text);
                oo.Update(Info);
                oo.Dispose();
                db1.Close();
                Response.Write("<script>alert('保存成功！！！');</script>");
                HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "插入", "Info", Info.AccountId + "|" + Info.Content + "|" + Info.Infoid + "|" + Info.AddDate, "../Magage/InfoAdd.aspx");

                Response.Write("<script>window.opener.location.reload();window.close();</script>");
            }
        }
    }
    //protected void butSave_Click(object sender, EventArgs e)
    //{
    //    Db db = new Db();
    //    Grove.ORM.ObjectOperator oo = db.GetObjectOperator();
    //    HZ.MBSM.Model.Info Info = new HZ.MBSM.Model.Info();
    //    Info.Infoid = Convert.ToInt64(txtInfoId.Text);
    //    Info.Title = txtTitle.Text;
    //    Info.Content = txtContent.Text;
    //    Info.AccountId = Convert.ToInt64(txtAccountId.Text); 
    //    Info.AddDate = Convert.ToDateTime(txtAddDate.Text);
    //    oo.Update(Info);        
    //    oo.Dispose();
    //    db.Close();
    //    Response.Write("<script>alert('保存成功！！！');</script>");

    //    Response.Write("<script>window.opener.location.reload();window.close();</script>");



    //}
}
